package com.encuestas;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.bd.dal;
import com.bd.estadistica;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.CustomLabelFormatter;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;
import com.medios.imark.encuesta.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;

public class statics extends Activity {
	GraphViewData[] datos;
	GraphViewSeries exampleSeries;
	LineGraphView graphView;
	String[] labels;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.estadistica);
		
		dal  dto  = new dal(this);
	List<estadistica> resul = dto.getEstadisticasCompletadas();
	if(resul.size()>0)
	{
		labels= new String [resul.size()];
		datos = new GraphViewData[resul.size()];
		try
		{
		 for(int i = 0; i< resul.size();i++)
		 {
			 estadistica  esta= resul.get(i);
			 datos[i]= new GraphViewData(i, esta.getConteoYerminadas());
			 labels[i]= esta.fechaFormatCorto();
			 
		 }
		}
		catch(Exception e)
		{
			Log.e("Error de datos vista", e.getMessage());
		}
		 exampleSeries = new GraphViewSeries(datos);
		 graphView= new LineGraphView(this, "Encuesta termiandas segun fecha");
	
		 graphView.setDrawDataPoints(true);
		 graphView.setHorizontalLabels(labels);
		 graphView.setDataPointsRadius(10f);
		 //graphView.setViewPort(2, 40);
		 graphView.setDrawBackground(true);
		 graphView.addSeries(exampleSeries);
		 graphView.getGraphViewStyle().setNumHorizontalLabels(5);
		 graphView.setScrollable(true);
		 graphView.setScalable(true);
		graphView.setViewPort(0, 4);
		
		 
		 final SimpleDateFormat dateFormatshor = new SimpleDateFormat("MMM d");
		 graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
			
			@Override
			public String formatLabel(double value, boolean isValueX) {
				if(isValueX)
				{
					Date fec = new Date((long)value);
					return dateFormatshor.format(fec);
				}
				return null;
				
			}
		});
		 
		 LinearLayout layo = (LinearLayout)findViewById(R.id.graph1);
		 layo.addView(graphView);
	
		
	}
	
	
		
		
		
		
	}

	
	
	
	
}
